package com.visitor.web.controller;

import com.github.pagehelper.PageInfo;
import com.visitor.bean.SmartUser;
import com.visitor.bean.VideoFlowing;
import com.visitor.bean.Visitor;
import com.visitor.service.VideoFlowingService;
import com.visitor.web.vm.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@Api(tags="出入影像管理")
@Controller
@RequestMapping(value = "videoFlowingManager")
public class VideoFlowingController {

	@Autowired
	private VideoFlowingService videoFlowingService;

	@GetMapping("/videoFlowingList")
	public ModelAndView videoFlowingList(@RequestParam(name = "pageNum",defaultValue = "1") int pageNum,
								  @RequestParam(name = "pageSize", defaultValue = "10") int pageSize,
								  VideoFlowing videoFlowing, ModelAndView modelAndView){

		PageInfo<VideoFlowing> data= videoFlowingService.getAllByPage(pageNum, pageSize, videoFlowing);
		modelAndView.addObject("page",data);
		modelAndView.setViewName("videoFlowing/videoFlowing-list");
		return modelAndView;
	}

	@ApiOperation(value = "按照编号删除影像信息",notes = "按照编号删除影像信息")
    @ApiImplicitParam(name="id",value="预约编号",paramType="path",required=true)
	@ResponseBody
	@PostMapping("/delVideoFlowing/{id}")
	public Response<String> delUser(@PathVariable("id")Long id){
		videoFlowingService.deleteVideoFlowingById(id);
		return Response.ok("success");
	}

	@ApiOperation(value = "添加影像信息",notes = "添加影像信息")
	@ResponseBody
	@PostMapping("/addVideoFlowing")
	public Response<String> addVideoFlowing(VideoFlowing videoFlowing){
		return videoFlowingService.saveOrUpdate(videoFlowing);
	}

	// 跳转到影像添加页面
	@GetMapping("/videoFlowing-add")
	public ModelAndView videoFlowingAddHtml(ModelAndView modelAndView){
		modelAndView.setViewName("videoFlowing/videoFlowing-add");
		return modelAndView;
	}

	// 跳转到影像编辑页面
	@GetMapping("/videoFlowing-edit")
	public ModelAndView videoFlowingEditHtml(Long id,ModelAndView modelAndView) {
		VideoFlowing videoFlowing = videoFlowingService.findVideoFlowingById(id);
		modelAndView.addObject("videoFlowing",videoFlowing);
		modelAndView.setViewName("videoFlowing/videoFlowing-edit");
		return modelAndView;
	}

	@ApiOperation(value="按照编号修改用户影像页面",notes="按照编号修改用户影像页面")
	@ApiImplicitParam(name="id",value="用户编号",paramType="path",required=true)
	@ResponseBody
	@PostMapping("/updateVideoFlowing")
	public Response<String> updateVideoFlowing(VideoFlowing videoFlowing, HttpSession session){
		session.setAttribute("videoFlowing",videoFlowing);
		return videoFlowingService.saveOrUpdate(videoFlowing);
	}


}
